function [finalThr, stdError, counts]=concatenateABRs(dataABR,animals,frequencyValues,imgDays)

nFreq=length(frequencyValues);
nDays=length(imgDays);
nAnimals=length(animals);

thrABR=nan(2*nAnimals,nFreq,nDays);

for ani=1:nAnimals
    animalStr=animals{ani,:};
    for dd=1:nDays
        dayStr=imgDays{dd,:};
        if ~isfield(dataABR.(animalStr),dayStr)
            continue
        end
        for freq=1:nFreq
            freqStr=['freq_' num2str(round(frequencyValues(freq)))];
            if isfield(dataABR.(animalStr).(dayStr).left,freqStr)
                thrABR(2*ani-1,freq,dd)=dataABR.(animalStr).(dayStr).left.(freqStr).threshold;
            end
            if isfield(dataABR.(animalStr).(dayStr).right,freqStr)
                thrABR(2*ani,freq,dd)=dataABR.(animalStr).(dayStr).right.(freqStr).threshold;
            end
        end
    end
end

counts=squeeze(sum(~isnan(thrABR(:,1,1)),1));
finalThr=squeeze(nanmean(thrABR,1));
stdError=squeeze(nanstd(thrABR,1))./sqrt(counts);